package com.example.rabbitmq.example.rabbitmq.hello;

import com.rabbitmq.client.*;

import java.io.IOException;

public class HelloConsumeConsumer {

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new  ConnectionFactory();
        //%2f 是虚拟主机 /
        factory.setUri("amqp://admin:admin@192.168.1.3:5672/%2f");
        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();
        channel.queueDeclare("queue1", false, false, true, null);

        channel.basicConsume("queue1", new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery delivery) throws IOException {
                System.out.println(consumerTag);
                System.out.println(new String(delivery.getBody()));
            }
        } ,consumerTag->{});
        channel.close();
        connection.close();
    }
}
